package com.ruoyi.logistic.controller;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.domain.vo.TableVo;
import com.ruoyi.common.service.TableService;
import com.ruoyi.logistic.domain.NetworkSettlementDetail;
import com.ruoyi.logistic.domain.PageDate;
import com.ruoyi.logistic.domain.PageInfo;
import com.ruoyi.logistic.domain.vo.NetworkSettlementDetailVo;
import com.ruoyi.logistic.service.INetworkSettlementDetailService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/network/settlement")
@RestController
@Api(tags = "网点财务_出港发件费结算_出港结算明细")
public class NetworkSettlementDetailController {
    @Autowired
    private INetworkSettlementDetailService networkSettlementDetailService;
    @Autowired
    private TableService tableService;
    @ApiOperation("显示出港结算明细列表")
    @GetMapping("/selectNetworkPullUniformAll")
    public R selectAll(PageDate pageDate){
        List<NetworkSettlementDetail> networkSettlementDetails = networkSettlementDetailService.selectAll(pageDate);
        if (networkSettlementDetails == null || networkSettlementDetails.size() == 0){
            return R.fail("暂无数据");
        }else {
            return R.ok(PageInfo.info(networkSettlementDetails));
        }
    }
    @ApiOperation("添加出港结算明细")
    @PostMapping("/insertNetworkSettlementDetail")
    public R insertNetworkPullUniform(@RequestBody NetworkSettlementDetail networkSettlementDetail){
        Boolean isAdd = networkSettlementDetailService.insert(networkSettlementDetail);
        if (isAdd){
            return R.ok("添加成功");
        }else {
            return R.fail("添加失败");
        }
    }
    @ApiOperation("修改出港结算明细")
    @PostMapping("/updateNetworkSettlementDetail")
    public R updateNetworkPullUniform(@RequestBody NetworkSettlementDetail networkSettlementDetail){
        Boolean isUpdate = networkSettlementDetailService.update(networkSettlementDetail);
        if (isUpdate){
            return R.ok("修改成功");
        }else {
            return R.fail("修改失败");
        }
    }
    @ApiOperation("删除出港结算明细")
    @PostMapping("/deleteNetworkSettlementDetail")
    public R deleteNetworkSettlementDetail(Integer id){
        Boolean isDelete = networkSettlementDetailService.deleteById(id);
        if (isDelete){
            return R.ok("删除成功");
        }else {
            return R.fail("删除失败");
        }
    }
    @ApiOperation("搜索出港结算明细")
    @PostMapping("/search")
    public R search(@RequestBody NetworkSettlementDetailVo networkSettlementDetailVo){
        List<NetworkSettlementDetail> list = networkSettlementDetailService.search(networkSettlementDetailVo);
        List<TableVo> fieldList = tableService.getFieldAnnotation(new NetworkSettlementDetail());
        com.alibaba.fastjson.JSONObject jsonObject = new com.alibaba.fastjson.JSONObject();
        jsonObject.put("list", PageInfo.info(list));
        jsonObject.put("fields", fieldList);
        if (list == null || list.size() == 0) {
            return R.fail("暂无数据");
        } else {
            return R.ok(jsonObject);
        }
    }
}
